package com.techfansy.pickerTimer.Timer.utils;

import java.util.Date;
import java.util.List;

/**
 * Created by Administrator on 2018/5/3/003.
 */

public class TimerDate {
    private Date dateCurrent, dateSelect;
    // 添加大小月月份并将其转换为list,方便之后的判断
    String[] months_big = {"1", "3", "5", "7", "8", "10", "12"};
    String[] months_little = {"4", "6", "9", "11"};
    private List<String> list_big;
    private List<String> list_little;
    private boolean isThreeMonth ;

    public TimerDate(Date dateCurrent, Date dateSelect,boolean isThreeMonth) {
        this.dateCurrent = dateCurrent;
        this.dateSelect = dateSelect;
        this.isThreeMonth = isThreeMonth;
    }
    public TimerDate(Date dateCurrent, Date dateSelect) {
        this.dateCurrent = dateCurrent;
        this.dateSelect = dateSelect;

    }
    //判断是否小于三个月如果小于就返回ture如果大于就返回false
    public int getTime() {
        if (!isThreeMonth){
            return 2;
        }
        if (getTime(7775999, "<"))
            return 1;
        else if (getTime(0, ">"))
            return -1;
        else
            return 0;
    }

    private boolean getTime(long time, String obj) {
        boolean check;
        switch (obj) {
            case "<":
                check = dateCurrent.getTime()/1000 + time < dateSelect.getTime()/1000;
                break;
            case ">":
                check = dateCurrent.getTime()/1000 + time > dateSelect.getTime()/1000;
                break;
            case "=":
                check = dateCurrent.getTime()/1000 + time == dateSelect.getTime()/1000;
                break;
            default:
                check = true;
        }
        return check;
    }

    private int getDays(int year, int month) {
        if (list_big.contains(String.valueOf(month + 1))) {
            return 31;
        } else if (list_little.contains(String.valueOf(month + 1))) {
            return 30;
        } else {
            // 闰年
            if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {
                return 29;
            } else {
                return 28;
            }
        }
    }

    //获取两个月的时间差
    private int getMonth() {
        return getSelectMonth() - getCurrentMonth();
    }

    private int getCurrentMonth() {
        return dateCurrent.getMonth();
    }

    private int getSelectMonth() {
        return dateCurrent.getMonth();
    }
}
